package main

import (
	"log"
	"sync"
	"time"
)

//互斥锁sync.Mutex
//读写锁sync.RWMutex

var HcMutex sync.Mutex

func runMutex(id int) {
	log.Printf("[job id:%d][try to get lock]", id)
	HcMutex.Lock()
	log.Printf("[job id:%d][got lock][start working...]", id)
	time.Sleep(10 * time.Second)
	HcMutex.Unlock()
	log.Printf("[job id:%d][job done,unlock]", id)
}

func runHclock() {
	go runMutex(1)
	go runMutex(2)
	go runMutex(3)

}

func main() {
	runHclock()
	time.Sleep(600 * time.Second)
}
